package com.bjqh.edu.UI.Activity.StudentPersonal;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bjqh.edu.Base.AppConstants;
import com.bjqh.edu.Bean.Teacher;
import com.bjqh.edu.MainActivity;
import com.bjqh.edu.R;
import com.bjqh.edu.UI.Activity.Index.FreeReservationActivity;
import com.bjqh.edu.UI.Activity.Login.LoginActivity;
import com.bjqh.edu.UI.Utils.AppManager;
import com.bjqh.edu.adapter.MyTeacherAdapter;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

public class MySettingActivity extends AppCompatActivity {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_qx)
    TextView tvQx;
    @BindView(R.id.rl_top_tilte)
    RelativeLayout rlTopTilte;
    @BindView(R.id.btn_out_login)
    Button btnOutLogin;
    @BindView(R.id.ll_pass)
    LinearLayout llPass;
    @BindView(R.id.ll_op)
    LinearLayout llOp;
    @BindView(R.id.ll_about)
    LinearLayout llAbout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_my_setting);
        ButterKnife.bind(this);
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tvTitle.setText("我的设置");
        btnOutLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder normalDialog =
                        new AlertDialog.Builder(MySettingActivity.this).
                                setTitle("小主，别走啊~~？")
                                .setPositiveButton("确定",
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                OkGo.post(AppConstants.BASE_URL + "/sys/exit.shtml")
                                                        .tag(this)
                                                        .cacheKey("cacheKey")
                                                        .cacheMode(CacheMode.DEFAULT)
                                                        .execute(new StringCallback() {
                                                            @Override
                                                            public void onSuccess(String s, Call call, Response response) {
                                                                Log.e("退出登录 ",s);




                                                            }

                                                            @Override
                                                            public void onError(Call call, Response response, Exception e) {
                                                                super.onError(call, response, e);
                                                                Toast.makeText(MySettingActivity.this, "报告小主，服务器被外星人偷走啦~~", Toast.LENGTH_SHORT).show();
                                                            }
                                                        });

                                                Intent logoutIntent = new Intent(MySettingActivity.this, LoginActivity.class);
                                                logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                                                startActivity(logoutIntent);
                                            }
                                        });
                normalDialog.setNegativeButton("取消",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create();
                // 显示
                normalDialog.show();


            }
        });
        llPass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {



                Intent intent = new Intent(MySettingActivity.this, PerPasswordActivity.class);
                startActivity(intent);
            }
        });
        llOp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MySettingActivity.this, OpinionActivity.class);
                startActivity(intent);

            }
        });
llAbout.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent();
        intent.putExtra("url","http://47.95.14.28:8080/h5/AboutUs.html");
        intent.setClass(MySettingActivity.this, FreeReservationActivity.class);
        MySettingActivity.this.startActivity(intent);
    }
});
    }
}
